<!-- rightColumnActionsRenderer.vue -->
<script setup>
import { nextTick, onMounted, reactive, ref } from 'vue'

import { useUserStore } from '@vben/stores'

import { Switch } from 'ant-design-vue'
// 固定Props只接收params
const props = defineProps({
  params: Object,
})
const userStore = useUserStore()
const value = ref(props.params.value)
const row = reactive(props.params.data)

function getValue() {
  return value.value
}
const onChange = (val) => {
  value.value = val
  // 安全检查
  if (props.params && props.params.api && props.params.colDef && props.params.colDef.field && props.params.node) {
    // 使用AG Grid的setDataValue方法更新数据，确保触发cellValueChanged事件
    props.params.node.setDataValue(props.params.colDef.field, val)
  }
}

onMounted(() => {
  // 可选：自动聚焦或其他初始化逻辑
  nextTick(() => {})
})

defineExpose({ getValue })
</script>

<template>
  <div style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center">
    <Switch v-model:checked="value" @change="onChange" :disabled="!userStore.userInfo.category_arr.includes(1)" />
  </div>
</template>
